#include <vector>
#include <algorithm>

using namespace std;

class Solution
{
public:
    int findLHS(vector<int> &nums)
    {
        sort(nums.begin(), nums.end());
        int begin = 0, ret = 0;
        for (int end = 1; end < nums.size(); ++end)
        {
            if (nums[end] - nums[begin] > 1)
            {
                ++begin;
            }
            if (nums[end] - nums[begin] == 1)
            {
                ret = max(end - begin + 1, ret);
            }
        }
        return ret;
    }
};